# -*- coding: utf-8 -*-


import  os
import sys
import glob

import config

class Dirs:
  
  def __init__(self, cfgfile):
    cfg = config.Config(cfgfile)
    #print cfg.getOption('project','name')
    #print cfg.getOption('project','basedir')
    #print cfg.getOption('database','username')
    self.base =  os.getcwd() + "\\" + cfg.getOption('project','template_dir')
  #cfg.setOption('option2','1')

  def getSublist(self, subdir=None):
      dirlist = []
      if subdir:        
        path = self.base +"\\"+ subdir
      else:
        path = self.base
        
      #print path
      list = glob.glob(path+"\\*")
      for item in list:
        dict = {}
        dict['path'] = item
        dict['name'] = os.path.basename(item)  #item
        dict['isdir'] = os.path.isdir(item)
        dirlist.append(dict)
      
        #for i in dirlist:
        #print i['isdir']
        #print i['name']
        #print os.path.basename( i['path']) 
      
      return dirlist
      
      #print list
  
if __name__ == "__main__":
  t  = Dirs('project.cfg')
  
  list = t.getSublist(None)
  for i in list:
    if i['isdir']:
      list1 = t.getSublist(i['name'])
  
